﻿using UnityEngine;
using System.Collections;

public class DestroyOnCollision : MonoBehaviour {

	public GameObject effect;
	public string[] excluded_tags;
	public string[] excluded_layers;
	
	void OnCollisionEnter2D (Collision2D c) {
	
		// tags
		foreach(string tag in excluded_tags)
		{
			if(c.gameObject.tag == tag)
				return;
		}
		// layers
		foreach(string lay in excluded_layers)
		{
			if(c.gameObject.layer == LayerMask.NameToLayer(lay))
				return;
		}
		
		// effect
		GameObject clone;
		if(effect!=null)
		{
			clone = Instantiate(effect,transform.position,transform.rotation)as GameObject;
			Destroy (clone,1);
		}
		
		
		Destroy (gameObject);
	
	}
}
